// Convoy Related Scripts, runs on server only

_group = createGroup west;

while {true} do {

		sleep (konvoyrespawnzeit*60);
		_soldatvar = 0;
		konvoy_marker_active = 1;
		deleteVehicle konvoytruck;
		konvoytruck = "Truck5tReammo" createVehicle getPos konvoystartpos;

		// Configure the Convoy Vehicle
		konvoytruck setVehicleInit
			"konvoytruck = this;
			this setVehicleVarName ""konvoytruck"";
			this setAmmoCargo 0;
			this setVehicleLock ""LOCKED"";
			clearWeaponCargo this;
			clearMagazineCargo this;
			removeAllWeapons this;"
		;

		// Configure the Convoy Driver
		deleteVehicle konvoysoldat;
		"SoldierW" createUnit [getpos konvoystartpos, group soldat1, "konvoysoldat = this", 1.0, "PRIVATE"];
		[konvoysoldat] join _group;
		konvoysoldat moveInDriver konvoytruck;
		konvoysoldat doMove getpos konvoyend;
		removeAllWeapons konvoysoldat;
		konvoysoldat addWeapon "M9";
		konvoysoldat addMagazine "15Rnd_9x19_M9";
		konvoysoldat addMagazine "15Rnd_9x19_M9";
		processInitCommands;

		// The Different Convoy Scenarios
		while {true} do {

			// Convoy is Hijacked
			if ((!(konvoysoldat in konvoytruck)) and (_soldatvar == 0)) 
				then {
				"hint localize ""STRS_konvoy_hijacked""; konvoytruck setVehicleLock ""UNLOCKED"";"
				call ISSE_pub_execPstr;
				_soldatvar = 1;
				};

			konvoytruck setFuel 1;

			// Convoy Arrives at Hijack Drop-off
				if (konvoytruck distance konvoybox <= 30) 
				exitWith {
					"hint localize ""STRS_konvoy_civarrived"";
					[konvoybox, 6, 0, 0] execVM ""convoyUnload.sqf"";"
					call ISSE_pub_execPstr;
				};

			// Convoy is Destroyed
			if (GETDAMMAGE konvoytruck >= 0.8)  
				exitWith {
					"[konvoytruck,45,false] execVM ""ammo_burn.sqf"";
					hint localize ""STRS_konvoy_destroyed"";"
					call ISSE_pub_execPstr;
					};

			// Convoy Arrives at Police Base
			if (konvoytruck distance konvoyend <= 10) 
				exitWith {
					"hint localize ""STRS_konvoy_arrived"";"
					call ISSE_pub_execPstr;
					(format ["if (iscop) then {Kontostand = Kontostand + 5000; hint localize ""STRS_konvoy_moneymehr"";};"]) call ISSE_pub_execPstr;
				};

			sleep 2;
		};

		sleep 2;

		// Disable the Vehicle when it Reaches a Drop-off
		"konvoytruck setFuel 0;"

		// Kick Players out of the Vehicle
		call ISSE_pub_execPstr;
		sleep 10;
		"if (player in konvoytruck) then {player ACTION [""eject"", konvoytruck];};"
		call ISSE_pub_execPstr;
		sleep 2;
		"if (player in konvoytruck) then {player ACTION [""eject"", konvoytruck];}; konvoytruck lock true;"
		call ISSE_pub_execPstr;

		// Hide the Convoy Until it is Needed Again
		sleep 120;
		konvoy_marker_active = 0;
		konvoytruck setpos getpos konvoyinsel;

};